	--os.loadAPI("/System/API/sysbar")
	os.loadAPI('/System/API/contexts')
	os.loadAPI('/System/API/windows')
	local xSize, ySize = term.getSize()
	local xCenter = math.floor(xSize/2)
	local yCenter = math.floor(ySize/2)
	local index = 'FarWeb'
	local resPath = '.ds/'..l_login..'/FarWeb.apk/Resources'
	local mainPath = resPath.."/mainPage.html"
	local starterPage = 'file:'..resPath..'/mainPage.html'
	local history = {}
	local tags = {}
	local i = 0
	local file = nil
	local yPos = 1
	local lng = 0
	local pageIndex = 1
	history[1] = starterPage
	local webScreen = window.create(term.current(),1,3,xSize-1,ySize-2)
	local screenSize = ySize-2
	local topBar = window.create(term.current(),1,1,xSize,2)
	local bottomBar = window.create(term.current(),1,ySize,xSize,1)
	local textAlign = 'left'
	local textColor = colors.black
	local links = {}
	local link = nil
	local buttons = {}
	local pos = 3
	local lenthScroll = 0
	local posScroll = 0
	local step = 0
	local header = false
	local inpFields = {}

	local clear = function(scr,color)
		scr.setBackgroundColor(color)
		scr.clear()
		scr.setCursorPos(1,1)
	end

	local text = function(str,x,y)
		term.setCursorPos(x,y)
		term.write(str)
	end

	local function scrollBar(count, size, pos, sizeStep, color2, color1)
		local lenthScroll = 0
		local posScroll = 0
		local lenthPage = 0
		local step = 0
		if color1 == nil then
			color1 = colors.white
		end
		if color2 == nil then
			color2 = colors.lightGray
		end
		paintutils.drawLine(xSize,3,xSize,ySize,color2)
		if count>0 then
			if count*size > ySize-3 then
				lenthPage = count*size
				lenthScroll = math.floor((ySize-2)/(lenthPage/(ySize-2)))
				step = ((ySize-3)-lenthScroll)/math.floor((lenthPage-(ySize-3))/sizeStep)

			else
				step = 0
				lenthScroll = ySize-2
			end
		else
			lenthScroll = ySize-2
		end
		paintutils.drawLine(xSize,3-pos,xSize,3+lenthScroll-pos,color1)
		return step
	end

	local textBar = function(str,x,y)
		topBar.setCursorPos(x,y)
		topBar.write(str)
	end

	local function textToTable(text)
	  local words = {}
		local pos = 1

		if #text > 1 then
			for i = 1, #text do
				if string.sub(text,i,i) ~= " " and string.sub(text,i,i) ~= '\
' then
					if words[pos] == nil then
						words[pos] = ""
					end
					words[pos] = words[pos]..string.sub(text,i,i)
				elseif string.sub(text,i,i) == "\
" and not(string.sub(text,i-1,i-1) == string.sub(text,i,i)) then
					if pos > 1 then
						pos = pos + 1
					end
					words[pos] = string.sub(text,i,i)
				elseif string.sub(text,i,i) == " " then
					--if pos > 1 then
						--if string.sub(text,i-1,i-1) ~= nil and string.sub(text,i-1,i-1) ~= '' and string.sub(text,i-1,i-1) == " " then
							--words[pos] = ''
						if string.sub(text,i-1,i-1) ~= '' and string.sub(text,i-1,i-1) ~= " " then
							pos = pos + 1
						end
					--else
					--	words[pos] = ' '
					--end
				end
			end
		elseif #text == 1 then
			if text ~= ' ' then
				words[1] = text
			end
		end
		if #words == 0 then
			words = nil
		end
	  return words
	end

	local function textPrinter(text,y,colorT,colorB,align,nl)
		if link then
			webScreen.setTextColor(colors.blue)
		elseif colorT then
	    webScreen.setTextColor(colorT)
	  end
	  if colorB then
		  webScreen.setBackgroundColor(colorB)
	  end
	  local words = textToTable(text)
	  local lines = {}
		if words then

			local pos = 0
			local gx, gy = webScreen.getCursorPos()
			local startLink = 0
			if nl == true then
				--if gy < y then
					--y = gy
				--end
				gx=gx-1
				pos = gx
				if align == 'center' then
					y=y+1
					gy=y
					pos = 1
					gx=0
				end
			else
				gx=0
				--gy=y
				y=y+1
				gy=y
				pos = 1
			end

		  local elms = 1

		  lines[1] = ''
		  for i=1, #words do
				if words[i] then
					pos = pos + #words[i]
					if words[i] == "\
" then
						elms = elms + 1
			      lines[elms] = ""
			  		pos = 0
					elseif pos <= xSize-1 then
						lines[elms] = lines[elms]..words[i].." "
						pos = pos+1
					else
			      --lines[elms] = string.sub(lines[elms],1,#lines[elms]-1)
						elms = elms + 1
			      lines[elms] = words[i].." "
			  		pos = #words[i]
					end
				end
			end
			local newLink = false
			if link then
				startLink = #links+1
				if not startLink then
					startLink = 1
				end
				if (links[startLink-1] and links[startLink-1]['href'] ~= link) or not links[startLink-1] then
					newLink = true
				--[[for i=1,#lines do

				end]]
					links[startLink] = {}
					links[startLink]['y1'] = y
					links[startLink]['x1'] = gx+1
					links[startLink]['href'] = link
				end
			end

			 if align == 'justify' then
				 	local ps = gx+1
			     for i=1,#lines do
			         if #lines[i] < xSize-3-ps and #lines[i] > math.floor(xSize/2 + xSize/5) then
			             local j = 1
			             local space = 0
			             while j < #lines[i] and #lines[i] <= xSize-3 do
			                 if j < #lines[i] and string.sub(lines[i],j,j) == ' ' then
			                     lines[i] = string.sub(lines[i],1,j)..string.sub(lines[i],j,#lines[i])
			                      j = j + 3 + space
			                  else
			                      j = j + 1
			                  end
			                  if j >= #lines[i] then
			                      j = 1
			                      space = space + 1
			                  end
			              end
			          end
								ps = 0
			      end
			  end

				    for i=1, #lines do
							if header then
								lines[i] = string.upper(lines[i])
							end
			        if align == 'center' then
			          webScreen.setCursorPos(math.floor(xSize/2-#lines[i]/2)+1,i+y-1)
			        elseif align == 'right' then
			          webScreen.setCursorPos(xSize-#lines[i]+1,i+y-1)
			        else
								webScreen.setCursorPos(gx+1,i+y-1)
								gx = 0
							end
					    webScreen.write(lines[i])
			      end
						if nl == true then
							nl = 0
						else
							nl = 1
						end
						gx, gy = webScreen.getCursorPos()
						if link and newLink then
							links[startLink]['y2'] = gy
							links[startLink]['x2'] = gx
						end
			  return gy
			else
				local gx, gy = webScreen.getCursorPos()
				return gy
			end
		end

	local function drawInputField(size,type,value,br,input)
		local gx,gy = webScreen.getCursorPos()
		if br==false then
			gy = gy+1
			gx=1
			yPos = yPos+1
		end
		size = math.floor(size/2)
		webScreen.setBackgroundColor(colors.white)
		if input then
			webScreen.setTextColor(colors.lightBlue)
		else
			webScreen.setTextColor(colors.lightGray)
		end
		webScreen.setCursorPos(gx,gy)
		--[[webScreen.write(string.char(141))
		for i=2,size-1 do
			webScreen.write(string.char(140))
		end
		webScreen.write(string.char(142))]]
		webScreen.write(string.char(149))
		if value then
			if type == 'password' or type == 'passwd' then
				for i=1,#value do
					webScreen.write(string.char(7))
				end
			else
				webScreen.write(value)
			end
		end
		webScreen.setCursorPos(gx+size-1,gy)
		webScreen.write(string.char(149))
		webScreen.setCursorPos(gx+size,gy)
		if input == nil then
			inpFields[#inpFields+1] = {}
			inpFields[#inpFields]['type'] = type
			inpFields[#inpFields]['x1'] = gx
			inpFields[#inpFields]['x2'] = gx+size-1
			inpFields[#inpFields]['y'] = gy
			if value then
				inpFields[#inpFields]['value'] = value
			else
				inpFields[#inpFields]['value'] = ''
			end
		end
	end

	local drawBar = function()
		topBar.setBackgroundColor(colors.lightBlue)
		topBar.clear()
		topBar.setTextColor(colors.white)
		textBar(string.char(17)..' '..string.char(16),1,2)
		textBar(index,1,1)
		textBar('File',5,2)
		topBar.write(' Page')
		topBar.write(' History')
		topBar.setTextColor(colors.lightGray)
		if pageIndex == #history then
			textBar(string.char(16),3,2)
		end
		if pageIndex <= 1 then
			textBar(string.char(17),1,2)
		end
		topBar.setBackgroundColor(colors.white)
		topBar.setCursorPos(12,1)
		for i=12,xSize do
			topBar.write(' ')
		end
		textBar(history[pageIndex],13,1)
		if #history[pageIndex] > xSize-12 then
			topBar.setCursorPos(xSize-2,1)
			topBar.write('..')
		end
		topBar.setTextColor(colors.gray)
		textBar(string.char(26),xSize,1)
	end

	local drawBBar = function()
		bottomBar.setBackgroundColor(colors.white)
		bottomBar.clear()
		bottomBar.setTextColor(colors.red)
		bottomBar.setCursorPos(xSize,1)
		bottomBar.write('x')
		bottomBar.setTextColor(colors.gray)
		bottomBar.setCursorPos(1,1)
		bottomBar.write('Loading...')
		local percent = 0
		local x = 0
		while lng <= 0 do
			bottomBar.setCursorPos(12,1)
			bottomBar.write('-')
			sleep(0)
			bottomBar.setCursorPos(12,1)
			bottomBar.write("\\")
			sleep(0)
			bottomBar.setCursorPos(12,1)
			bottomBar.write('|')
			sleep(0)
			bottomBar.setCursorPos(12,1)
			bottomBar.write('/')
			sleep(0)
		end
		while lng > 0 and percent < 100 do
			bottomBar.clear()
			percent = math.floor((i*100)/lng)
			x = (percent*xSize)/100
			bottomBar.setCursorPos(1,1)
			bottomBar.setTextColor(colors.lightBlue)
			bottomBar.setBackgroundColor(colors.white)
			for i=1,x do
				bottomBar.write(string.char(140))
			end
			bottomBar.setCursorPos(math.floor(xSize/2),1)
			bottomBar.write(percent..'%')
		end
		sleep(5)
	end

	local getCode = function(path)
		if string.sub(path,1,4) == 'http' then
			file = http.get(path)
		elseif string.sub(path,1,5) == 'file:' then
			file = fs.open(string.sub(path,6,#path),'r')
		else
			file = http.get('http://'..path)
			history[pageIndex] = 'http://'..path
			if not file or #file.readAll() == 0 then
				file = http.get('https://'..path)
				history[pageIndex] = 'https://'..path
			end
			drawBar()
		end
		if file then
			file = file.readAll()
			if string.sub(file,1,1) ~= '{' then
				lng = #file
				i = 1
					local attrIndex = 1
					local x = 1
					local y = 1
					local deep = 0
					local str = ''
					local tagName = ''
					local tagIndex = 1
					local attr = {}
					local tag = {}
					local text = ''
					local scriptCheck = false
					local styleCheck = false
					while i <= #file-1 do
						tag = {}
						if string.sub(file,i,i) == '<' then
							deep = deep + 1
							i = i+1
							local ended = false
							while string.sub(file,i,i) ~= ' ' do
								if string.sub(file,i,i) == '>' then
									ended = true
									break
								else
									tagName = tagName..string.sub(file,i,i)
								end
								i = i+1
							end
							tag['name'] = string.lower(tagName)
							if tagName == 'script' then
								scriptCheck = true
							elseif tagName == '/script' then
								scriptCheck = false
							elseif tagName == 'style' then
								styleCheck = true
							elseif tagName == '/style' then
								styleCheck = false
							end
							--sleep(0)
							if i == #file then
								tags[tagIndex] = tag
								break
							end
							if not scriptCheck and not styleCheck and not ended then
								while string.sub(file,i,i) ~= '>' do
									i = i+1
									while string.sub(file,i,i) ~= ' ' and string.sub(file,i,i) ~= '>' do
										str = ''
										while string.sub(file,i,i) ~= '=' and string.sub(file,i,i) ~= '>' and string.sub(file,i,i) ~= ' ' do
											str = str..string.sub(file,i,i)
											i = i+1
										end
										local attrName = str
										--attr[attrIndex]['name'] = str
										str = ''
											if string.sub(file,i,i) == '=' then
												i = i+1
												if string.sub(file,i,i) == '"' then
													i=i+1
													while string.sub(file,i,i) ~= '"' do
														str = str..string.sub(file,i,i)
														i = i+1
													end
												elseif string.sub(file,i,i) == "'" then
													i=i+1
													while string.sub(file,i,i) ~= "'" do
														str = str..string.sub(file,i,i)
														i = i+1
													end
												end
												i=i+1
											end
											--attr[attrIndex]['value'] = str
											--attrIndex = attrIndex + 1
											attr[string.lower(attrName)] = str
									end
								end
								tag['attr'] = attr
							end
						end
						str = ''
						tags[tagIndex] = tag
						attr = {}
						str = ''
						attrIndex = 1
						tagIndex = tagIndex+1
						i=i+1
						if string.sub(file,i,i) ~= '<' then
							while string.sub(file,i,i) ~= '<' do
								if not scriptCheck and tagName ~= "style" then
									str = str..string.sub(file,i,i)
								end
								i = i+1
							end
							if not scriptCheck and not styleCheck then
								tags[tagIndex] = str
								str = ''
								tagIndex = tagIndex + 1
							end
						end
						tagName = ''
					end
				--[[local h = fs.open('/serPage.txt','w')
				h.write(textutils.serialize(tags))
				h.close()]]
				lng = 0
			else
				tags=textutils.unserialize(file)
			end
		else
			windows.attention('Attention','Unable to load page')
		end
	end

	--[[local redraw = function()
		--clear(webScreen,colors.white)
		yPos = 1
		--webScreen.setBackgroundColor(colors.lightGray)
		--webScreen.clear()
		webScreen.write('n')
		local j = 1
		while j <= #tags do
			if type(tags[i]) == 'string' then
				local bPos = yPos
				webScreen.write('t')
				yPos = yPos + textPrinter(tags[j],bPos,textColor,colors.white,textAlign)
				j = j+1
			else
				webScreen.write('f')
				if tags[j]['name'] == 'title' then
					j=j+1
					title = tags[j]
				end
				j=j+1
			end
		end
		drawBar()
	end]]

	local function load()
		local function gtCode()
			tags = {}
			index = 'FarWeb'
			getCode(history[pageIndex])
		end
		local function stoper()
			while true do
				local event, side, x, y = os.pullEvent()
				if event == 'mouse_click' then
					if x == xSize and y == ySize then
						break
					end
				end
			end
		end
		parallel.waitForAny(gtCode,drawBBar,stoper)
		i = 0
		file = nil
		yPos = 1
		pos = 3
		posScroll = 0
		webScreen.reposition(1,pos)
		webScreen.setTextColor(colors.black)
		webScreen.setBackgroundColor(colors.white)
		webScreen.clear()
		local j = 1
		--lng = #tags
		link = nil
		links = {}
		buttons = {}
		inpFields = {}
		screenSize = ySize - 2
		yPos = 1
		webScreen.setCursorPos(1,1)
		local br = true
		local algTag = ''
		while #tags > 1 and j <= #tags do
			--webScreen.write(type(tags[j]))
			--sleep(0)
			if type(tags[j]) == 'string' and tags[j] ~= ' ' --[[and tags[j] ~= '\
' ]]then
				--[[if link then
					textColor = colors.blue
				else
					textColor = colors.black
				end]]
				local oldP = yPos
				local oldx, oldy = webScreen.getCursorPos()
				yPos = textPrinter(tags[j],oldP,textColor,colors.white,textAlign,br)
				if yPos > screenSize then
					webScreen.reposition(1,3,xSize-1,yPos)
					webScreen.setCursorPos(oldx,oldy)
					textPrinter(tags[j],oldP,textColor,colors.white,textAlign,br)
				end
				br = true
			else
				if tags[j]['attr'] and tags[j]['attr']['align'] then
					textAlign = tags[j]['attr']['align']
					algTag = tags[j]['name']
				end
				if textAlign == 'center' then
					if tags[j]['name'] == '/'..algTag then
						textAlign = 'left'
					end
				end
				if tags[j]['name'] == 'title' then
					--j=j+1
					index = tags[j+1]
					j=j+1
					if not string.find(history[#history],resPath) and not string.find(history[#history],'file:') and pageIndex >= #history then
						local his = fs.open(resPath..'/history.html','r')
						if his then
							local txt = his.readAll()
							his.close()
						end
						if txt and txt~='' and string.sub(txt,1,6) == '<title' then
							txt = txt..'<br><a href="'..history[#history]..'">'..index..'</a>'
						else
							txt = '<title>History</title><br><a href="'..history[#history]..'">'..index..'</a>'
						end
						his = fs.open(resPath..'/history.html','w')
						his.write(txt)
						his.close()
					end
				elseif tags[j]['name'] == 'a' then
					if tags[j]['attr'] then
						if tags[j]['attr']['href'] then
							link = tags[j]['attr']['href']
						end
					end
				elseif tags[j]['name'] == '/a' then
					link = nil
				elseif tags[j]['name'] == 'br' or tags[j]['name'] == 'li' or tags[j]['name'] == 'tr' or tags[j]['name'] == 'div'then
					br = false
				elseif tags[j]['name'] == 'h1' or tags[j]['name'] == 'h2' or tags[j]['name'] == 'h3' or tags[j]['name'] == 'h4' then
					br = false
					header = true
					yPos = yPos+1
				elseif tags[j]['name'] == '/h1' or tags[j]['name'] == '/h2' or tags[j]['name'] == '/h3' or tags[j]['name'] == '/h4' then
					br = false
					header = false
					yPos = yPos+1
				elseif tags[j]['name'] == 'p' or tags[j]['name'] == '/p' then
					br = false
					yPos = yPos+1
				elseif tags[j]['name'] == 'input' then
					if tags[j]['attr'] and tags[j]['attr']['type'] and tags[j]['attr']['type']~='hidden' and (tags[j]['attr']['type'] == 'text' or tags[j]['attr']['type'] == 'password' or tags[j]['attr']['type'] == 'passwd' or tags[j]['attr']['type'] == 'email') then
						drawInputField(30,tags[j]['attr']['type'],tags[j]['attr']['value'],br)
					elseif not tags[j]['attr'] or not tags[j]['attr']['type'] then
						if tags[j]['attr'] then
							if tags[j]['attr']['value'] then
								drawInputField(30,'text',tags[j]['attr']['value'],br)
							end
						end
					elseif tags[j]['attr']['type'] == 'submit' then
						local gx,gy = webScreen.getCursorPos()
						if br == false then
							gx=1
							gy=gy+1
							yPos=yPos+1
						end
						buttons[#buttons+1] = {}
						buttons[#buttons]['type'] = tags[j]['attr']['type']
						buttons[#buttons]['y'] = gy
						buttons[#buttons]['x1'] = gx
						local texts = 'Submit'
						if tags[j]['attr']['value'] then
							texts = tags[j]['attr']['value']
						end
						webScreen.setBackgroundColor(colors.lightGray)
						webScreen.write(' '..texts..' ')
						webScreen.setBackgroundColor(colors.white)
						gx,gy = webScreen.getCursorPos()
						buttons[#buttons]['x2'] = gx
					end
					br = true
				elseif tags[j]['name'] == 'button' then
					local gx,gy = webScreen.getCursorPos()
					--[[if br then
						gx=1
						gy=gy+1
						yPos=yPos+1
					end]]
					buttons[#buttons+1] = {}
					if tags[j]['attr'] and tags[j]['attr']['type'] then
						buttons[#buttons]['type'] = tags[j]['attr']['type']
					end
					buttons[#buttons]['y'] = gy
					buttons[#buttons]['x1'] = gx
					local texts = ''
					j=j+1
					while tags[j]['name'] ~= '/button' do
						if type(tags[j]) == 'string' then
							texts = texts..tags[j]..' '
						end
						j = j+1
					end
					local oldP = yPos
					yPos = textPrinter(texts,oldP,textColor,colors.lightGray,textAlign,true)
					if yPos > screenSize then
						webScreen.reposition(1,3,xSize-1,yPos)
						textPrinter(texts,oldP,textColor,colors.lightGray,textAlign,true)
					end
					gx,gy = webScreen.getCursorPos()
					buttons[#buttons]['x2'] = gx
					br = true
				end
			end
			j=j+1
		end
		drawBar()
	end

	local running = function()
		while true do
			event, side, x, y = os.pullEvent()
			if event == "mouse_click" then
				if x <= 1 and y==2 and pageIndex > 1 then
					pageIndex = pageIndex - 1
					load()
				elseif x == 3 and y == 2 and pageIndex < #history then
					pageIndex = pageIndex + 1
					load()
				elseif x == xSize and y == 1 then
					load()
				elseif x >= 5 and x <= 8 and y == 2 then
					term.setBackgroundColor(colors.gray)
					term.setTextColor(colors.white)
					text(' File ',4,2)
					local fMenu = contexts.main(4,3,'Save Page','Exit')
					if fMenu == 'Save Page' then
						if #tags > 0 then
							webScreen.redraw()
							topBar.redraw()
							local path = windows.input(math.floor(xSize/2-10),math.floor(ySize/2-3),'Save as',16,{"Path",""})
							if path[1] > '' then
								local h = fs.open(path[1],'w')
								if h then
									h.write(textutils.serialize(tags))
									h.close()
									webScreen.redraw()
									topBar.redraw()
									windows.attention('Success','Page saved as '..path[1])
								end
							end
						else
							windows.error('Nothing to save')
						end
					elseif fMenu == 'Exit' then
						break
					end
				elseif x >= 10 and x <= 13 and y == 2 then
					term.setBackgroundColor(colors.gray)
					term.setTextColor(colors.white)
					text(' Page ',9,2)
					local fMenu = contexts.main(9,3,'Undo','Redo','Reload')
					if fMenu == 'Reload' then
						webScreen.redraw()
						topBar.redraw()
						load()
					elseif fMenu == 'Undo' and pageIndex > 1 then
						pageIndex = pageIndex - 1
						load()
					elseif fMenu == 'Redo' and pageIndex < #history then
						pageIndex = pageIndex + 1
						load()
					end
				elseif x >= 15 and x <= 21 and y == 2 then
					term.setBackgroundColor(colors.gray)
					term.setTextColor(colors.white)
					text(' History ',14,2)
					pageIndex = pageIndex + 1
					if #history > pageIndex then
						for i=pageIndex+1,#history do
							history[i] = nil
						end
					end
					history[pageIndex] = 'file:'..resPath..'/history.html'
					sleep(0)
					webScreen.redraw()
					topBar.redraw()
					drawBar()
					load()
				elseif x >= 12 and x <= xSize-1 and y == 1 then
					topBar.setBackgroundColor(colors.white)
					topBar.setCursorPos(12,1)
					for i=12,xSize do
						topBar.write(' ')
					end
					topBar.setCursorPos(13,1)
					term.setBackgroundColor(colors.white)
					local inp = read()
					if inp and inp > '' then
						pageIndex = pageIndex + 1
						if #history > pageIndex then
							for i=pageIndex+1,#history do
								history[i] = nil
							end
						end
						history[pageIndex] = inp
						drawBar()
						load()
					else
						drawBar()
					end
				elseif y >= 3 then
					for i=1,#links do
						local lnk = false
						if links[i]['y1']==links[i]['y2'] then
							if x>=links[i]['x1'] and x<=links[i]['x2'] and y==links[i]['y1']+pos-1 then
								lnk = true
								f='1'
							end
						else
							if y>links[i]['y1']+pos-1 and y<links[i]['y2']+pos-1 then
								lnk = true
								f='2'
							elseif y==links[i]['y1']+pos-1 and x>=links[i]['x1'] then
								lnk = true
								f='3'
							elseif y==links[i]['y2']+pos-1 and x<=links[i]['x2'] then
								lnk = true
								f='4'
							end
						end

						--if (f1 and not(f2 or f3 or f4)) or (f2 and not(f1 or f3 or f4)) or (f3 and not (f1 or f2 or f3)) or (f4 and not(f1 or f2 or f3)) then
						if lnk then
							pageIndex = pageIndex + 1
							if #history > pageIndex then
								for i=pageIndex+1,#history do
									history[i] = nil
								end
							end
							if string.sub(links[i]['href'],1,4) == 'http' then
								history[pageIndex] = links[i]['href']
							elseif string.sub(links[i]['href'],1,2) == '..' then
								local j = #history[pageIndex-1]
								while j > 1 do
									if string.sub(history[pageIndex-1],j,j) == '/' then
										break
									else
										j=j+1
									end
								end
								local prevPath = string.sub(links[i]['href'],1,j)
								history[pageIndex] = prevPath..links[i]['href']
							elseif string.sub(links[i]['href'],1,1) == '/' then
								local count = 0
								local pos = 0
								for j=1,#history[pageIndex-1] do
									if string.sub(history[pageIndex-1],j,j) == '/' then
										count = count + 1
									end
									if count == 3 then
										pos = j
										break
									end
								end
								history[pageIndex] = string.sub(history[pageIndex-1],1,pos-1)..links[i]['href']
							else
								history[pageIndex] = history[pageIndex-1]..links[i]['href']
							end
							drawBar()
							load()
							break
						end
					end
					for i=1,#inpFields do
						if x>=inpFields[i]['x1'] and x<=inpFields[i]['x2'] and y==inpFields[i]['y']+pos-1 then
							local gx,gy = webScreen.getCursorPos()
							webScreen.setCursorPos(inpFields[i]['x1'],inpFields[i]['y'])
							drawInputField(30,nil,inpFields[i]['value'],true,true)
							webScreen.setTextColor(colors.lightGray)
							webScreen.setBackgroundColor(colors.white)
							term.setCursorPos(inpFields[i]['x1']+1,inpFields[i]['y']+pos-1)
							webScreen.setCursorPos(inpFields[i]['x1']+1,inpFields[i]['y'])
							for j=1,15-2 do
								webScreen.write(' ')
							end
							webScreen.setCursorPos(inpFields[i]['x1']+1,inpFields[i]['y'])
							if inpFields[i]['type'] == 'text' or inpFields[i]['type'] == 'email' then
								inpFields[i]['value'] = read()
							elseif inpFields[i]['type'] == 'password' or inpFields[i]['type'] == 'passwd' then
								inpFields[i]['value'] = read(string.char(7))
							end
							webScreen.setCursorPos(inpFields[i]['x1'],inpFields[i]['y'])
							drawInputField(30,nil,inpFields[i]['value'],true,false)
							webScreen.setCursorPos(gx,gy)
							webScreen.redraw()
							break
						end
					end
				end
			elseif event == 'mouse_scroll' then
				if step > 0 then
					if side == 1 and pos > -yPos+ySize-2 then
						posScroll = posScroll - step
						pos = pos - 1
						webScreen.reposition(1,pos)
					elseif side == -1 and pos < 3 then
						posScroll = posScroll +step
						pos = pos + 1
						webScreen.reposition(1,pos)
						if pos > 3 then
							pos = 3
						end
					end
				end
			end
			step = scrollBar(yPos,1,posScroll,1)
			webScreen.redraw()
			topBar.redraw()
		end
	end

	--redraw()
	step = scrollBar(yPos,1,posScroll,1)
	drawBar()
	webScreen.setBackgroundColor(colors.white)
	webScreen.clear()
	load()
	running()